
class TreeView {
    constructor(){
        this.init();
    }

    // 初始化Tree
    init () {
        this.bindSelector();
        this.initData();

    }

    initData () {
        //var defer = $.Deferred();
        $.when($.ajax({
            url: "tree/info",
            success: (result)=> {
                this.TreeData = result.rows;
                //defer.resolve();
            },
        })).then(()=> {
            this.tree.treeview({
                data: this.TreeData
            })
        }).then(()=>{
            this.tree.on("nodeSelected", (event, node) => {
                console.log(1111)
                console.log(node)
                if (node.nodes == undefined) {
                    //没有子节点 、 打开当前节点
                    console.log(node)
                } else {
                    //有子节点、打开当前节点的子节点
                    console.log(node)
                    currentDir = this.getCurrentDir(node);
                    enterDir(currentDir);
                }
            });
        });
    }

    bindSelector() {
        this.tree = $("#left-side-tree");
    }

    // 根据 text 获取 全路径
    getCurrentDir (node) {
        var nodeId = node.nodeId;
        var wholePath = [node.text];
        while (true) {
            // console.log(node.parentId === undefined)
            if (node.parentId === undefined) break;
            var parentNode = this.tree.treeview('getParent', node.nodeId);
            wholePath.unshift(parentNode.text);
            console.log(parentNode)
            node = parentNode;
        }
        return wholePath.join("/");
    }
}